class Solution:
    def romanToInt(self, s: str) -> int:
        dic={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
        a=10000
        val=0
        for i in s:
            if dic[i]<=a:
                val+=dic[i]
            else:
                val+=dic[i]
                val-=2*a
            a=dic[i]
        return val